import utils from '../../../utils';
const { getContextComponents } = utils;

export default [
  {
    weight: 0,
    type: 'checkbox',
    label: 'Is Dymic',
    tooltip: '',
    key: 'isDymic',
    input: true,
  },
  {
    weight: 2,
    type: 'select',
    input: true,
    tooltip: '',
    key: 'dymicType',
    label: 'Type',
    data: {
      values: [
        { label: 'Key', value: '1' },
        // { label: 'URL', value: '2' }
      ],
    },
    customConditional(context) {
      return context.data.isDymic;
    },
  },
  {
    weight: 3,
    type: 'select',
    input: true,
    key: 'refreshOn',
    label: 'Refresh List On',
    tooltip: 'Refresh data when another field changes.',
    dataSrc: 'custom',
    valueProperty: 'value',
    data: {
      custom(context) {
        var values = [];
        if (context.row.isDymic && context.row.dymicType != 1) {
          values.push({ label: 'Any Change', value: 'data' });
        }

        context.utils.eachComponent(
          context.instance.options.editForm.components,
          function (component, path) {
            if (component.key !== context.data.key) {
              values.push({
                label: component.label || component.key,
                value: path,
              });
            }
          },
        );
        return values;
      },
    },
    customConditional(context) {
      return context.data.isDymic;
    },
  },
  {
    weight: 4,
    type: 'textfield',
    label: 'load url',
    key: 'dymicLoad.url',
    placeholder: 'load url',
    tooltip: '',
    input: true,
    customConditional(context) {
      return context.data.isDymic && context.data.dymicType == 2;
    },
  },
  {
    weight: 5,
    type: 'datagrid',
    input: true,
    label: 'dymac queries',
    key: 'dymicLoad.queries',
    tooltip: '',
    components: [
      {
        label: 'Key',
        key: 'key',
        input: true,
        type: 'textfield',
      },
      // {
      //   type: 'checkbox',
      //   label: 'Is Dymic',
      //   tooltip: '',
      //   key: 'isDymic',
      //   input: true,
      // },
      // {
      //   label: 'value',
      //   key: 'value',
      //   input: true,
      //   type: 'textfield',
      // },
      {
        type: 'select',
        input: true,
        label: 'who',
        key: 'who',
        dataSrc: 'custom',
        valueProperty: 'value',
        data: {
          custom(context) {
            const components = getContextComponents(context);
            return components;
          },
        },
        // customConditional(context) {
        //   console.log(arguments)
        // },
      },
    ],
    customConditional(context) {
      return context.data.isDymic && context.data.dymicType == 2;
    },
  },
  {
    weight: 4,
    type: 'textfield',
    label: 'Data path',
    key: 'dymicLoad.dataPath',
    placeholder: 'data path',
    tooltip: '',
    input: true,
    customConditional(context) {
      return context.data.isDymic && context.data.dymicType == 2;
    },
  },
  {
    type: 'textfield',
    label: 'Default Value',
    key: 'defaultValue',
    ignore: true,
    weight: 5,
    placeholder: 'Default Value',
    tooltip:
      'The will be the value for this field, before user interaction. Having a default value will override the placeholder text.',
    input: true,
    customConditional(context) {
      return !context.data.isDymic;
    },
  },
  {
    key: 'multiple',
    ignore: true,
  },
];
